<!--TVM日结账单据录入-->
<template>
  <div class="TVMRiJieDanJuInput preView el-card is-always-shadow el-card__body">
    <el-dialog
      title="TVM日结账单据录入"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-form v-if="isReload" class="TVMRiJieDanJuInputForm" :option="option" v-model="formData">
        <template slot-scope="scope" slot="lineCode">
          <span>{{ getLineName(formData.lineCode)}}</span>
        </template>
        <template slot-scope="scope" slot="stationCode">
         <span>{{getStationName(formData.lineCode,formData.stationCode)}}</span>
        </template>
        <template slot-scope="scope" slot="startTime1">
          <span>{{moment(formData.startTime).format('YYYY-MM-DD')}}</span>
        </template>
        <template slot-scope="{row}" slot="tvmCode">
         <span>{{row.tvmCode}}</span>
        </template>
        <template slot-scope="{row}" slot="receiveNotes">
         <span>{{row.receiveNotes}}</span>
        </template>
        <template slot-scope="{row}" slot="receiveCoin">
         <span>{{row.receiveCoin}}</span>
        </template>
        <template slot-scope="{row}" slot="noteChangen">
         <span>{{row.noteChangen}}</span>
        </template>
        <template slot-scope="{row}" slot="coinChange">
         <span>{{row.coinChange}}</span>
        </template>
        <template slot-scope="{row}" slot="faultRefundAmount">
         <span>{{row.faultRefundAmount}}</span>
        </template>
        <template slot-scope="{row}" slot="receiveTotalMoney">
         <span>{{row.receiveTotalMoney}}</span>
        </template>
        <template slot-scope="{row}" slot="sellTicketTotalMoney">
         <span>{{row.sellTicketTotalMoney}}</span>
        </template>
        <template slot-scope="{row}" slot="rechargeMoney">
         <span>{{row.rechargeMoney}}</span>
        </template>
        <template slot-scope="{row}" slot="changeTotalMoney">
         <span>{{row.changeTotalMoney}}</span>
        </template>
        <template slot-scope="{row}" slot="startTime">
         <span>{{row.startTime}}</span>
        </template>
        <template slot-scope="{row}" slot="endTime">
         <span>{{row.endTime}}</span>
        </template>
        <template slot-scope="{row}" slot="faultRefundAmount">
         <span>{{row.faultRefundAmount}}</span>
        </template>
        <template slot-scope="{row}" slot="rechargeMoney">
         <span>{{row.rechargeMoney}}</span>
        </template>
        <template slot-scope="{row}" slot="sellTicketMoney">
         <span>{{row.sellTicketMoney}}</span>
        </template>
        <template slot-scope="{row}" slot="startTime">
         <span>{{row.startTime}}</span>
        </template>
        <template slot-scope="{row}" slot="endTime">
         <span>{{row.endTime}}</span>
        </template>
        <template slot-scope="scope" slot="menuForm" v-if="showType==3">
          <el-button type="primary" @click="closed">返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";
  import moment from "moment";
  import {
    fenExYuangettoFixed,
    getgetStationCodes,
    getLineCodes, getLineName, getStationName,
    getSwPmDeviceOperationCodeList,
    qianxiangType
  } from "../../../../../api/subwayRat/commonCheck";
  import { dateFormat } from '@/util/date'
  import {
    addSwStTvmDailyBills,
    getSwStTvmDailyBillCashPayList,
    getSwStTvmDailyBillElectronicPayList
  } from "../../../../../api/subwayRat/TVMRevenueVarianceAudit.TvmChaYiDXC/TVMRiJieDanJuInput";

  export default {
    components:{
    },
    data() {
      return {
        isReload:true,
        //1编辑，2添加，3预览
        showType:1,
        dialogVisible:true,
        lineCodes:[],
        stationCodes:[],
        tvmCodes:[],
        formData:{
          dynamic: [],
          dynamic2: []
        },
        option:{
        }
    }
    },
    created() {


    },
    methods: {
      moment,
      getLineName,
      getStationName,
      async recallShow(id,row,showType){
        this.showType=showType;
        this.getOption();
        this.formData={}
        debugger
       Object.assign(this.formData,row);
        //获取现金数据
        await getSwStTvmDailyBillCashPayList({relationId:id}).then((res)=>{
          this.formData.dynamic=res.data.data; //
//          this.formatterAmountCashs(this.formData.dynamic,true);
        }).catch((e)=>{
          this.$message.error("获取数据失败！");
        });
        //获取电子数据
        await getSwStTvmDailyBillElectronicPayList({relationId:id}).then((res)=>{
            debugger
          this.formData.dynamic2 = res.data.data; //
//          this.formatterAmountElectrons(this.formData.dynamic2,true);
        }).catch((e)=>{
          this.$message.error("获取数据失败！");
        })
      },
      formatterAmountCashs(rows,isYuan){ //格式化钱
        // rows=JSON.parse(rows);
        if(isYuan){
          for(let i=0;i<rows.length;i++){
            let row=rows[i];
            row.receiveNotes=fenExYuangettoFixed(row,'receiveNotes');
            row.receiveCoin=fenExYuangettoFixed(row,'receiveCoin');
            row.noteChangen=fenExYuangettoFixed(row,'noteChangen');
            row.faultRefundAmount=fenExYuangettoFixed(row,'faultRefundAmount');
            row.receiveTotalMoney=fenExYuangettoFixed(row,'receiveTotalMoney');
            row.sellTicketTotalMoney=fenExYuangettoFixed(row,'sellTicketTotalMoney');
            row.rechargeMoney=fenExYuangettoFixed(row,'rechargeMoney');
            row.changeTotalMoney=fenExYuangettoFixed(row,'changeTotalMoney');
            row.coinChange=fenExYuangettoFixed(row,'coinChange');
          }
        }else if(!isYuan){
          for(let i=0;i<rows.length;i++){
            let row=rows[i];
            row.receiveNotes=Number(row.receiveNotes)*100;
            row.receiveCoin=Number(row.receiveCoin)*100;
            row.noteChangen=Number(row.noteChangen)*100;
            row.faultRefundAmount=Number(row.faultRefundAmount)*100;
            row.receiveTotalMoney=Number(row.receiveTotalMoney)*100;
            row.sellTicketTotalMoney=Number(row.sellTicketTotalMoney)*100;
            row.rechargeMoney=Number(row.rechargeMoney)*100;
            row.changeTotalMoney=Number(row.changeTotalMoney)*100;
            row.coinChange=Number(row.coinChange)*100;

          }
        }
        return JSON.stringify(rows);
      },
      formatterAmountElectrons(rows,isYuan){ //格式化钱
        // rows=JSON.parse(rows);
        if(isYuan){
          for(let i=0;i<rows.length;i++){
            let row=rows[i];
            row.faultRefundAmount=fenExYuangettoFixed(row,'faultRefundAmount');
            row.rechargeMoney=fenExYuangettoFixed(row,'rechargeMoney');
            row.sellTicketMoney=fenExYuangettoFixed(row,'sellTicketMoney');
          }
        }else if(!isYuan){
          for(let i=0;i<rows.length;i++){
            let row=rows[i];
            row.faultRefundAmount=Number(row.faultRefundAmount)*100;
            row.rechargeMoney=Number(row.rechargeMoney)*100;
            row.sellTicketMoney=Number(row.sellTicketMoney)*100;
          }
        }
        return JSON.stringify(rows);
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isPreview=false;
      },
      getOption(){
        this.option={
          submitBtn:this.showType!=3,
          emptyBtn:false,
          group:[
            {
              icon:'',
              label: '',
              // collapse:false,
              prop: 'group1',
              column: [{
                label: '线路名称',
                prop: 'lineCode',
                labelWidth:130,
                formslot:true,
              },{
                label: '站点名称',
                prop: 'stationCode',
                // width:250,
                labelWidth:130,
                formslot:true,
              },{
                label: '录入时间',
                prop: 'startTime1',
                // width:'250',
                labelWidth:130,
                formslot:true,
              }]
            },
            {
              icon:'',
              sortable:true,
              label: '现金支付',
              // collapse:false,
              width:600,
              span:24,

              prop: 'group2',
              column: [{
                label: '',
                prop: 'dynamic',
                type: 'dynamic',
                children: {
                  addBtn:false,
                  delBtn:false,
                  index:false,
                  sortable:true,
                  align: 'center',
                  headerAlign: 'center',
                  column: [
                    // {width:150,label:"tvm编号",prop:"tvmCode",formslot: true ,disabled: this.showType==3},

                    {width:150,label:"接收纸币",
                      prop:"receiveNotes",formslot: true},

                    {width:150,label:"接收硬币",
                      prop:"receiveCoin",formslot: true},

                    {width:150,label:"纸币找零",
                      prop:"noteChangen",formslot: true},

                    {width:150,label:"硬币找零",
                      prop:"coinChange",formslot: true},

                    {width:150,label:"故障退款",
                      prop:"faultRefundAmount",formslot: true},

                    {width:150,label:"接收总计",
                      prop:"receiveTotalMoney",formslot:true},

                    {width:150,label:"售票总计",
                      prop:"sellTicketTotalMoney",formslot: true},

                    {width:150,label:"充值总计",
                      prop:"rechargeMoney",formslot: true},

                    {width:150,label:"找零总计",
                      prop:"changeTotalMoney",formslot:true},

                    // {width:150,label:"开始时间",
                    //   prop:"startTime",formslot: true},
                    //
                    // {width:150,label:"结束时间",
                    //   prop:"endTime",formslot: true},
                  ]
                }
              }
              ]
            },
            {
              icon:'',
              sortable:true,
              label: '电子支付',
              // collapse:false,
              width:600,
              span:24,
              prop: 'group3',
              column: [{
                label: '',
                prop: 'dynamic2',
                type: 'dynamic',
                children: {
                  addBtn:false,
                  delBtn:false,
                  sortable:true,
                  align: 'center',
                  headerAlign: 'center',
                  column: [
                    // {width:150,label:"tvm编号",
                    //   prop:"tvmCode",formslot: true},
                    {label:"故障退款",
                      prop:"faultRefundAmount",formslot: true},
                    {label:"充值总计",
                      prop:"rechargeMoney",formslot: true},
                    {label:"售票总计",
                      prop:"sellTicketMoney",formslot: true},
                    // {width:150,label:"开始时间",
                    //   prop:"startTime",formslot: true},
                    // {width:150,label:"结束时间",
                    //   prop:"endTime",formslot: true},
                  ]
                }
              }
              ]
            }
          ]
        } ;
        this.isReload=false;
        this.$nextTick(()=>{
          this.isReload=true;
        })
      },
      clearForm(){
        this.formData={dynamic:[],dynamic2: []};
      }
    },
    mounted() {
      getLineCodes().then(res=>{ //获取线路
        this.lineCodes=res;
      });
    }
  }
</script>
<style lang="scss">
  .TVMRiJieDanJuInput.preView{
    .avue-group[index='2']{
      .avue-form__group{
        .avue-form__row{
          width: 100%;
        }
      }
    }
    .avue-group[index='3']{
      .avue-form__group{
        .avue-form__row{
          width: 100%;
        }
      }
    }

  }

</style>
